from django.db import models


# Create your models here.
class Demo(models.Model):
    demo_text = models.CharField(max_length=200)
    demo_date = models.DateTimeField('date')


# 统计
class CountItem(models.Model):
    editor_num = models.IntegerField(verbose_name='编辑次数')
    item_num = models.IntegerField(verbose_name='内容数目')
    discuss_num = models.IntegerField(verbose_name='讨论数目')
    count_key = models.CharField(max_length=10, default='', verbose_name='key')

    def __str__(self):
        return self.count_key

    class Meta:
        verbose_name = '数据统计'
        verbose_name_plural = '数据统计'


# 新闻
class New(models.Model):
    new_title = models.CharField(max_length=20, verbose_name='新闻标题')
    new_content = models.TextField(verbose_name='新闻内容')
    new_date = models.DateTimeField(auto_now_add=True, verbose_name='发布时间')

    def __str__(self):
        return self.new_title

    class Meta:
        ordering = ['-new_date']
        verbose_name = '新闻'
        verbose_name_plural = '新闻'


# 家乡内容
class ContentItem(models.Model):
    item_theme = models.CharField(max_length=10, verbose_name='主题')
    item_title = models.CharField(max_length=20, verbose_name='标题')
    item_content = models.TextField(verbose_name='内容')
    item_editor_id = models.CharField(max_length=10, verbose_name='发布者')
    item_date = models.DateTimeField(auto_now_add=True, verbose_name='发布时间')

    def __str__(self):
        return self.item_title

    class Meta:
        ordering = ['-item_date']
        verbose_name = '内容'
        verbose_name_plural = '内容'


# 讨论
class Disscuss(models.Model):
    discuss_date = models.DateTimeField(auto_now_add=True, verbose_name='发布时间')
    discuss_content = models.TextField(verbose_name='内容')
    discuss_commit_id = models.CharField(max_length=10, verbose_name='发布者')
    discuss_title = models.CharField(max_length=20, default=None, verbose_name='标题')
    discuss_theme = models.CharField(max_length=10, default=None, verbose_name='主题')

    def __str__(self):
        return self.discuss_content

    class Meta:
        ordering = ['-discuss_date']
        verbose_name = '讨论'
        verbose_name_plural = '讨论'


# 小知识
class Tip(models.Model):
    tip_content = models.TextField(max_length=50, verbose_name='内容')

    def __str__(self):
        return self.tip_content

    class Meta:
        verbose_name = '小知识'
        verbose_name_plural = '小知识'


# 用户
class User(models.Model):
    user_id = models.CharField(max_length=128, unique=True, verbose_name='用户名')
    user_psw = models.CharField(max_length=256, verbose_name='密码')
    user_email = models.EmailField(unique=True, verbose_name='邮箱地址')
    user_create_date = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    user_type = models.CharField(max_length=8, default="用户", verbose_name='用户组')
    is_contribute = models.CharField(max_length=4, default="no", verbose_name='是否贡献')
    editor_times = models.IntegerField(default=0, verbose_name='编辑次数')
    discuss_num = models.IntegerField(default=0, verbose_name='讨论数目')
    content_num = models.IntegerField(default=0, verbose_name='内容数目')
    user_real_name = models.CharField(max_length=12, unique=False, verbose_name='真实姓名', default='')

    def __str__(self):
        return self.user_id

    class Meta:
        ordering = ["-user_create_date"]
        verbose_name = "用户"
        verbose_name_plural = "用户"


# 操作历史
class ActionHistory(models.Model):
    action_starter = models.CharField(max_length=20, verbose_name='操作者')
    action_type = models.CharField(max_length=8, verbose_name='类型')
    action_date = models.DateTimeField(auto_now_add=True, verbose_name='时间')
    action_target = models.CharField(max_length=20, verbose_name='目标')
    action_theme = models.CharField(max_length=20, verbose_name='目标', default=None)

    def __str__(self):
        return self.action_starter + self.action_type

    class Meta:
        ordering = ['-action_date']
        verbose_name = '操作历史'
        verbose_name_plural = '操作历史'
